﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.Linq;

namespace DevEx
{
    public class CTCNX
    {
        private static QLVTDataContext GetDc()
        {
            QLVTDataContext dc = new QLVTDataContext();
            return dc;
        }
                
        public IQueryable<tblTCNX> SelectAllRecord(Boolean _isNhap)
        {
            QLVTDataContext dc = GetDc();

            var q = from p in dc.tblTCNXes
                    where p.IsNhap == _isNhap
                    select p;
            return q;
        }

        public IQueryable<tblTCNX> SelectAllRecord()
        {
            QLVTDataContext dc = GetDc();

            var q = from p in dc.tblTCNXes                    
                    select p;
            return q;
        }

        public tblTCNX SelectRecordByID(int ID_TCNX)
        {
            QLVTDataContext dc = GetDc();

            var q = (from p in dc.tblTCNXes where p.ID_TCNX == ID_TCNX select p).SingleOrDefault();
            return q;
        }

        //Insert
        public void Insert(tblTCNX obj)
        {
            QLVTDataContext dc = GetDc();
            dc.tblTCNXes.InsertOnSubmit(obj);
            dc.SubmitChanges();
        }
        //Delete
        public void Delete(int ID)
        {
            QLVTDataContext dc = GetDc();

            var DVT = dc.tblTCNXes.SingleOrDefault(p=>p.ID_TCNX == ID);
            dc.tblTCNXes.DeleteOnSubmit(DVT);
            dc.SubmitChanges();
        }
        //Update
        public void Update(tblTCNX obj)
        {
            QLVTDataContext dc = GetDc();
            dc.tblTCNXes.Attach(obj);
            dc.Refresh(RefreshMode.KeepCurrentValues, obj);
            dc.SubmitChanges(ConflictMode.ContinueOnConflict);
        }
    }
}
